package com.zhiyou.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class MyException implements HandlerExceptionResolver{

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		System.out.println("异常解析。。。。。");
		ex.printStackTrace();
		ModelAndView mav = new ModelAndView();
		mav.addObject("obj", handler);
		mav.addObject("error", ex);
		if(ex instanceof UnauthenticatedException){
		mav.setViewName("redirect:/login.jsp");
		}else if(ex instanceof UnauthorizedException){
		mav.setViewName("redirect:/error.jsp");
		}else{
		mav.setViewName("forward:/error.jsp");
		}
// TODO Auto-generated method stub
		
		return mav;
	}

}
